package com.smile.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smile.commons.page.MyBatisPlusPageConverter;
import com.smile.commons.page.R;
import com.smile.model.dto.request.EditAirportRequestDTO;
import com.smile.model.dto.request.GetAirportByIdRequestDTO;
import com.smile.model.dto.request.GetAirportListRequestDTO;
import com.smile.model.request.EditAirportRequest;
import com.smile.model.request.GetAirportByIdRequest;
import com.smile.model.request.GetAirportDetailInfoRequest;
import com.smile.model.request.GetAirportListRequest;
import com.smile.model.response.Drone;
import com.smile.model.response.GetAirportByIdResponse;
import com.smile.model.response.GetAirportListResponse;
import com.smile.model.response.GetDroneListResponse;
import com.smile.model.response.response.GetAirportByIdResponseDTO;
import com.smile.model.response.response.GetAirportListResponseDTO;
import com.smile.model.response.response.GetDroneListResponseDTO;
import com.smile.service.AirportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/drone")
public class DroneController {

    @Autowired
    private AirportService airportService;

    @Value("${spring.redis.host}")
    private String redisHost;
//    @SaIgnore
    @PostMapping("/getAirportById")
    public R<GetAirportByIdResponse> getAirportById(@RequestBody GetAirportByIdRequest getAirportByIdRequest) {
        System.out.println(redisHost);
        GetAirportByIdRequestDTO getAirportByIdRequestDTO = BeanUtil.copyProperties(getAirportByIdRequest, GetAirportByIdRequestDTO.class);
        GetAirportByIdResponseDTO getAirportByIdResponseDTO = airportService.getAirportById(getAirportByIdRequestDTO);
        GetAirportByIdResponse getAirportByIdResponse = BeanUtil.copyProperties(getAirportByIdResponseDTO, GetAirportByIdResponse.class);
        getAirportByIdResponse.setDroneList(BeanUtil.copyToList(getAirportByIdResponseDTO.getDroneDTOs(), Drone.class));
        getAirportByIdResponse.setWindDirection("东南风");
        return R.ok(getAirportByIdResponse);
    }



    @PostMapping("/getDroneList")
    public R<List<GetDroneListResponse>> getDroneList(@RequestBody GetAirportListRequest getAirportListRequest) {
        GetAirportListRequestDTO getAirportListRequestDTO = new GetAirportListRequestDTO();

        BeanUtil.copyProperties(getAirportListRequest, getAirportListRequestDTO);
        List<GetDroneListResponseDTO> pages = airportService.getDroneList(getAirportListRequestDTO);
        List<GetDroneListResponse> list = new ArrayList<>();
        for (GetDroneListResponseDTO feisuanAirport : pages) {
            GetDroneListResponse getAirportListResponseDTO = BeanUtil.copyProperties(feisuanAirport, GetDroneListResponse.class);
            System.out.println(getAirportListResponseDTO);
            list.add(getAirportListResponseDTO);
        }
        return R.ok(list);
    }

    @PostMapping("/getAllAirportList")
    public R<List<GetAirportListResponse>> getAllAirportList(@RequestBody GetAirportListRequest getAirportListRequest) {
        GetAirportListRequestDTO getAirportListRequestDTO = new GetAirportListRequestDTO();

        BeanUtil.copyProperties(getAirportListRequest, getAirportListRequestDTO);
        List<GetAirportListResponseDTO> pages = airportService.getAllAirportList(getAirportListRequestDTO);
        List<GetAirportListResponse> list = new ArrayList<>();
        for (GetAirportListResponseDTO feisuanAirport : pages) {
            GetAirportListResponse getAirportListResponseDTO = BeanUtil.copyProperties(feisuanAirport, GetAirportListResponse.class);
            System.out.println(getAirportListResponseDTO);
            list.add(getAirportListResponseDTO);
        }
        return R.ok(list);
    }
}
